<?php session_start(); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Parent Informer RCSHS - Parent Notification Lobby</title>

<link rel=stylesheet href="../../css-layouts/themes/defaulttheme.css" type="text/css">
<link rel=stylesheet href="../../css-layouts/headlinks.css" type="text/css">

<script src="../../jsc/mailjs.js" type="text/javascript"></script>
<script src="../../jsc/fademe.js" type="text/javascript"></script>

</head>

<body>

<div id="mainhead"><br><br><br></div>

<?php 

 require_once("../../sqlconfig.php");
 
 $testsite=@fsockopen("www.gmail.com", 80);
 if(!$testsite) {
  header("Location: net_err.php");
  die();
 }

 mysql_connect($server, $sqlusr, $sqlpass) or die(mysql_error()); 
 mysql_select_db($mydb) or die(mysql_error()); 

 //Checks if there is a login cookie
 if(isset($_COOKIE["parentinformerprcshs"]) || isset($_COOKIE["parentinformerurcshs"])) { 
  if(isset($_COOKIE["parentinformerprcshs"])) {
   $username = $_COOKIE["parentinformerprcshs"]; 
  }
  else {
   $_SESSION['theerrcode'] = 2;
   header("Location: ../logerr_atmpt.php");
  }
  $pass = $_COOKIE["parentinformerurcshs"];
  $check = mysql_query("SELECT * FROM logtbl WHERE usernm = '".$username."'") or die(mysql_error());
  while($info=mysql_fetch_array($check)) {
   if ($pass!=$info['pwrnd']) {
    $_SESSION['theerrcode'] = 2;
    header("Location: ../logerr_atmpt.php");
   }
   else {

    /*
     * A session cookie is set-up to produce the suitable notification
     * once the e-mail is passed through mailsending.php and is sent to
     * the recipient. The session cookie mailrefercode can only take place
     * as two values which is discussed in greater detail in mailsending.php.
     */
    $_SESSION['mailrefercode']=2;
	
	
    /*
     * Load the configuration XML file and then parse a MySQL query which
     * requests a table of the desired year level.
     */
    $conffile = "../xml/acadconf.xml";
    $xmlconf = simplexml_load_file($conffile) or die('<br>Unable to load configurations.');
    $nowyr = strstr($xmlconf->syr, '-', true);

    if($info['priv']==3) {
     header("Location: ../../");
    }

    /*
     * This statement reads the mail database for the respective
     * year level and appends the parent's e-mail to the TO
     * heading.
     */
    if(!$_GET['yrlvl'] && !$_GET['id']) {
     die("<br>Sorry. Cannot retrieve mailing variables.");
    }
    $mailquery = mysql_query("SELECT * FROM maildb".$_GET['yrlvl']."yr".$nowyr." WHERE thisid= '".$_GET['id']."'") or die(mysql_error());
    $fetchme = mysql_fetch_array($mailquery);
    $sentto = $fetchme['themail'];

    $namequery=mysql_query("SELECT * FROM ".$_GET['yrlvl']."yr".$nowyr." WHERE myid= '".$_GET['id']."'") or die(mysql_error());
    $studinfo=mysql_fetch_array($namequery);

    /*
     * Assign variables that would replace the "$" signs
     * in the format given by the user.
     */
 
    $lnm=$studinfo['lnm'];
    $fnm=$studinfo['fnm'];
    $mnmcut=substr($studinfo['mnm'], 0, 1);
	
	/*
	 * The following retrieves the subject name from the id given in
	 * the GET variables. It uses the XML list of subjects.
	 */
	$fileto = "../xml/subjects.xml";
	$xmlsubj = simplexml_load_file($fileto) or die('<br>Unable to load subjects list.');
	$subjid = $xmlsubj->xpath('//year[@level=\''.$_GET['yrlvl'].'\']/name');
	$subj = $subjid[$_GET['subj'] - 1];
	
	/* subjnstud reverts the original id of the subject
	 * relative to the grades CSV file. subjnstud represents
	 * the column where the grade of the student is located.
	 */	
	$subjnstud = $_GET['subj'] + 2;
	$recds = fopen("../recd/csv/".$_GET['yrlvl']."yr".$nowyr.".csv", "r");
	for($grcol=0;$grcol<=$_GET['id'];$grcol++) {
	 $grout = fgetcsv($recds, 1024);
	}
    $fg=$grout[$subjnstud];
	
	/*
	 * The following conditions test whether the grade obtained
	 * is passing or not according to the passing grade set by
	 * the user.
	 */
    if($fg>=$info['passgr']) {
    $actiontaken="PASSED";
    }
    else {
     $actiontaken="FAILED";
    }
   }

?>

<p class="leftnav">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Logged in as: <?php echo $_COOKIE["parentinformerprcshs"]; ?>
</p>

<p class="rightnav">

<?php

if($info['priv']==1) {
 echo "<a href='../acctmgnt'>Account Management</a> || ";
}

?>
<a href="../settings">Settings</a> || <a href="../redirout.php">Logout</a>
</p>

<hr style="clear: both;"><br>

<!--
  | The following statements define the overlay which contains
  | the password field and another submit button.
  -->

<div id="mailoverlay">
<form method=post id="passform" action="">

<div align=center>
Please enter the account password of the mail address in the<br>
FROM heading:<br>
<br>

<table>

<tr>
<td>PASSWORD: </td>
<td><input type="password" name="mailpass" id="mailpass"></td>
</tr>

</table>
</div>

</form>

<p align=center>
<br>
<input type="button" value="SUBMIT" onclick="chiasmuspass(); mailpass();">

<br><br>
Click <a href="#" onclick="fademeout('mailoverlay');">here</a> to re-edit mail.
</p>

</div>

<!--
  | The following statements define the mailing form where the
  | the user would write the mail to its recepients.
  -->

<center><font id="heading">PARENT NOTIFICATION</font></center>
<br>

<div align="center">
<form method=post id="mainform" name="mainform" action="">
<table>

<tr>
<td>FROM:</td>
<td><input type="text" name ="thetohead" size="65" maxlength="50" value="<?php echo $info['mailadd']; ?>"></td>
</tr>

<tr>
<td>TO: </td>
<td><input type="text" name="thefromhead" size="65" value="<?php echo $sentto; ?>"></td>
</tr>

<tr>
<td>SUBJECT:</td>
<td><input type="text" name="headme" size="65" value="<?php echo 'Parent Informer RCSHS - Academic Report - ' . $subj; ?>"></td>
</tr>

<tr>
<td></td>
<td>
<textarea rows="10" cols="50" name="mainmail">
<?php

 /*
  * Retrieve the default mail notification the user has set
  * and insert the variables above into the variables' place.
  */
  $convfunc=eval('return "'.addslashes($info['msgdef']).'";');
  echo $convfunc;

?>
</textarea>
</td>
</tr>

<tr>
<td></td>
<td><input type="button" value="SUBMIT" onclick="fademein('mailoverlay');"></td>
</tr>

</table>
</form>
</div>


<?php

  }
 }
 else {
  header("Location: ../../");
 }

?>

<br>

<div class="footnav" align=center>

<hr>

<a href="../../">Main Page</a> ||
<a href="#">Help</a> ||
<a href="../../externalaffairs/links.php">Links</a> ||
<a href="#">About</a>
<br>

<span id="copyme">
&copy; 2011 Roosevelt College Science High School. All rights reserved.
</span>

</div>

</body>
</html>